class FollowMouse2 extends egret.DisplayObjectContainer {
    private arrow:Arrow
    private vx:number = 0
    private vy:number = 0
    private force:number = 0.05

    public constructor() {
        super()
        this.once( egret.Event.ADDED_TO_STAGE, this.onAddToStage, this)
    }

    private onAddToStage(event:egret.Event) {
        this.arrow = new Arrow()
        this.arrow.x = this.stage.stageWidth / 2
        this.arrow.y = this.stage.stageHeight / 2
        this.addChild(this.arrow)

        this.stage.addEventListener( egret.TouchEvent.TOUCH_MOVE, ( evt:egret.TouchEvent )=>{
            let dx : number = evt.localX - this.arrow.x,
                dy : number = evt.localY - this.arrow.y,
                angle : number = Math.atan2(dy, dx),
                ax : number = Math.cos(angle) * this.force,
                ay : number = Math.sin(angle) * this.force
            
            this.arrow.rotation = angle * 180 / Math.PI
            this.vx += ax
            this.vy += ay
            this.arrow.x += this.vx
            this.arrow.y += this.vy
        }, this )

        this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this)
    }

    private onEnterFrame(event:egret.Event) {
    }
}